from pyecharts.charts import WordCloud, Line
import pyecharts.options as opts
from pyecharts.globals import SymbolType


class Frame_editor:

    line_chart = None
    wordcloud_chart = None

    def __init__(self):
        pass

    def create_line_chart(self, timeruler, timedata, filename):
        line = Line(init_opts=opts.InitOpts(bg_color='')).add_xaxis(
            xaxis_data=timeruler).add_yaxis(
            series_name="弹幕数量", y_axis=timedata,
            markpoint_opts=opts.MarkPointOpts(
                data=[opts.MarkPointItem(type_="max", name="最大值"), opts.MarkPointItem(type_="min", name="最小值"), ]),
            markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average", name="平均值")]),
        ).set_global_opts(title_opts=opts.TitleOpts(title="《" + filename + "》弹幕信息分析面板", subtitle="Made by Dragon King"),
                          tooltip_opts=opts.TooltipOpts(trigger="axis"),
                          toolbox_opts=opts.ToolboxOpts(is_show=False), legend_opts=opts.LegendOpts(type_="scroll"),
                          xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False), )
        self.line_chart = line

    def create_wordcloud_chart(self, barrage_ranking_dataset):
        wordcloud = WordCloud(
            init_opts=opts.InitOpts(bg_color='')).add(
            "", barrage_ranking_dataset, word_size_range=[20, 100], shape=SymbolType.DIAMOND).set_global_opts(
            title_opts=opts.TitleOpts())
        self.wordcloud_chart = wordcloud
